<?php
			
	class ClientesController extends ApplicationController {

		public $template="bodega";
		function index(){					
			$this->cliente=new Cliente();
		}
				

		public function agregar(){
			if($this->request("action")=="create"){			
				$cliente=new Cliente();
				$cliente->nombre=$this->request('nombre');
				$cliente->paterno=$this->request('paterno');
				$cliente->materno=$this->request('materno');
				$cliente->apodo=$this->request('apodo');
				$cliente->dni=$this->request('dni');
				$cliente->fechanacimiento=$this->request('fechanacimiento');
				$cliente->sexo=$this->request('sexo');
				$cliente->direccion=$this->request('direccion');
				$cliente->telefono=$this->request('telefono');
				$cliente->telefono_2=$this->request('telefono_2');
				$cliente->mail=$this->request('mail');
				$cliente->mail2=$this->request('mail2');
				if($cliente->create()){
					Flash::success("Cliente agregado");
				}else{
					Flash::error("Hubo un error al agregar el cliente");
				}
			}
			$this->render("index");
		}
		
		public function listar($page= ' '){
			$this->set_response("view");
	        $this->count = $this->Cliente->count();
	        if ($page == '') {
	            echo "AQUI";
	            $this->page = $this->Cliente->paginate('per_page: 3', 'page: 1');
	        } elseif ($page == 'next') {
	            $this->page = $this->Cliente->paginate('per_page: 3', "page: {$this->page->next}");
	        } elseif ($page == 'prev') {
	            $this->page = $this->Cliente->paginate('per_page: 3', "page: {$this->page->prev}");
	        }
		}
		
		
		public function buscar(){
			$nombre=$this->request("nombre");
			$this->set_response("view");
			$this->clientes=$this->Cliente->find("nombre like '%$nombre%' or paterno like '%$nombre%' or materno  like '%$nombre%' ");
		}
		
		public function ver_cuenta(){
			
		}
	}
	
?>
